﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zor_Modes;
using Zor_IDAL;
using Zor_Tools;
using System.Data;
using Dapper;

namespace Zor_DAL
{
    public class InvoiceRemake_DAL<T> where T : class
    {
      /// <summary>
      /// 列表
      /// </summary>
      /// <returns></returns>
        public static List<T> Invoice_Remake(string where)
      {
          string sql = null;
          if (where != null && where !="")
          {
               sql = "select * from  [V_InvoiceRemake] where Acceptance_TicketNumber = '" + where + "'";
          }
          else
          {
               sql = "select * from  [V_InvoiceRemake] where Acceptance_TicketNumber = null ";
          }
          
          List<T> list = DapperQuery<T>.DoQueryList(sql, null);
          return list;
      }
        /// <summary>
        /// 重录发票号列表
        /// </summary>
        /// <returns></returns>
        public static List<T> UpdateInvoice(int In_Id)
        {
           var sql = " select * from [V_InvoiceRemake] where In_Id = " + In_Id + " ";
            List<T> list_up = DapperQuery<T>.DoQueryList(sql, null);
            return list_up;
        }
        /// <summary>
        /// 更改发票号
        /// </summary>
        /// <returns></returns>
        public static List<T> Invoice_New(int In_Id, string InNumBer)
        {
            
            var sql = "if  exists(select In_Id  from [Zor_Invoice] where In_Id =" + In_Id + " ) ";
            sql += "update [Zor_Invoice] set In_NewNumber='" + InNumBer + "' where In_Id = " + In_Id + "";
            List<T> list_new = DapperQuery<T>.DoQueryList(sql, null);
            return list_new;
        }
        /// <summary>
        /// 第二次更改发票号
        /// </summary>
        /// <returns></returns>
        public static List<T> Invoice_Two(int In_Id, string InNumBer)
        {

            var sql = "if  exists(select In_Id  from [Zor_Invoice] where In_Id =" + In_Id + " ) ";
            sql += "update [Zor_Invoice] set In_TwoNumber='" + InNumBer + "' where In_Id = " + In_Id + "";
            List<T> list_new = DapperQuery<T>.DoQueryList(sql, null);
            return list_new;
        }
        /// <summary>
        /// 第三次更改发票号
        /// </summary>
        /// <returns></returns>
        public static List<T> Invoice_Three(int In_Id, string InNumBer)
        {

            var sql = "if  exists(select In_Id  from [Zor_Invoice] where In_Id =" + In_Id + " ) ";
            sql += "update [Zor_Invoice] set In_ThreeNumber='" + InNumBer + "' where In_Id = " + In_Id + "";
            List<T> list_new = DapperQuery<T>.DoQueryList(sql, null);
            return list_new;
        }
        /// <summary>
        /// 获取发票号
        /// </summary>
        /// <returns></returns>
        public static List<T> Invoice_Get(int In_Id)
        {

            var sql = "select * from [dbo].[Zor_Invoice] where In_Id =" + In_Id + " ";
            List<T> list_new = DapperQuery<T>.DoQueryList(sql, null);
            return list_new;
        }
    }
}